import 'package:equatable/equatable.dart';
import 'project.dart' show Priority;

/// 待办任务状态枚举
enum TodoStatus {
  todo('TODO', '待办'),
  inProgress('IN_PROGRESS', '进行中'),
  done('DONE', '已完成'),
  blocked('BLOCKED', '阻塞');

  const TodoStatus(this.code, this.description);
  final String code;
  final String description;
}

/// 任务类型枚举
enum TodoType {
  communication('COMMUNICATION', '沟通'),
  schedule('SCHEDULE', '排期'),
  document('DOCUMENT', '文档'),
  dataSource('DATA_SOURCE', '数据源'),
  develop('DEVELOP', '开发'),
  test('TEST', '测试'),
  uat('UAT', '用户验收'),
  release('RELEASE', '发布');

  const TodoType(this.code, this.description);
  final String code;
  final String description;
}

/// 待办任务实体类
class Todo extends Equatable {
  final int id;
  final int projectId;
  final String projectName;
  final String title;
  final String? description;
  final TodoStatus status;
  final Priority priority;
  final TodoType todoType;
  final String? assigneeName;
  final String reporterName;
  final DateTime? dueDate;
  final double? estimatedHours;
  final double? actualHours;
  final DateTime createTime;
  final DateTime updateTime;
  final bool isNearDeadline;

  const Todo({
    required this.id,
    required this.projectId,
    required this.projectName,
    required this.title,
    this.description,
    required this.status,
    required this.priority,
    required this.todoType,
    this.assigneeName,
    required this.reporterName,
    this.dueDate,
    this.estimatedHours,
    this.actualHours,
    required this.createTime,
    required this.updateTime,
    required this.isNearDeadline,
  });

  @override
  List<Object?> get props => [
        id,
        projectId,
        projectName,
        title,
        description,
        status,
        priority,
        todoType,
        assigneeName,
        reporterName,
        dueDate,
        estimatedHours,
        actualHours,
        createTime,
        updateTime,
        isNearDeadline,
      ];

  Todo copyWith({
    int? id,
    int? projectId,
    String? projectName,
    String? title,
    String? description,
    TodoStatus? status,
    Priority? priority,
    TodoType? todoType,
    String? assigneeName,
    String? reporterName,
    DateTime? dueDate,
    double? estimatedHours,
    double? actualHours,
    DateTime? createTime,
    DateTime? updateTime,
    bool? isNearDeadline,
  }) {
    return Todo(
      id: id ?? this.id,
      projectId: projectId ?? this.projectId,
      projectName: projectName ?? this.projectName,
      title: title ?? this.title,
      description: description ?? this.description,
      status: status ?? this.status,
      priority: priority ?? this.priority,
      todoType: todoType ?? this.todoType,
      assigneeName: assigneeName ?? this.assigneeName,
      reporterName: reporterName ?? this.reporterName,
      dueDate: dueDate ?? this.dueDate,
      estimatedHours: estimatedHours ?? this.estimatedHours,
      actualHours: actualHours ?? this.actualHours,
      createTime: createTime ?? this.createTime,
      updateTime: updateTime ?? this.updateTime,
      isNearDeadline: isNearDeadline ?? this.isNearDeadline,
    );
  }
}
